﻿@using Webdiyer.WebControls.Mvc
@model PagedList<NetSurveillance.WebApp.DataServices.Models.KeywordTemplate>
@{
    ViewBag.Title = Resources.MenuResource.SystemSetting_KeywordTemplateSetting;
    Layout = "~/Views/Shared/_SystemConfigLayout.cshtml";
    ViewBag.CurrentMainMenu = 5;
    ViewBag.CurrentMiddleMenu = 9;
}
<div style="text-align: right;padding-right: 5px;margin-bottom: 10px;">
    
</div>
<table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td width="95%">
            <table cellpadding="0" cellspacing="0" class="file_manage_tab" border="0">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>关键字</th>
                        <th>创建时间</th>
                        <th style="width: 180px;">&nbsp;&nbsp;</th>
                    </tr>
                </thead>
                <tbody id="tbodyEntries">
                    @foreach (var keywordTemp in Model)
                    {
                        <tr data-entryId="@keywordTemp.Id" class="chk_showdialog_td_center">
                            <td>@keywordTemp.Id</td>
                            <td>@keywordTemp.KeywordName</td>
                            <td>@keywordTemp.CreatedTime.ToShortDateString()</td>
                            <td style="text-align: center;">
                                <input class="btn_set" type="button" value="@Resources.Resource.Button_Alter" onclick="openEntry(@keywordTemp.Id)"/>
                                <input class="btn_set" type="button" value="@Resources.Resource.Button_Delete" onclick="deleteEntry(@keywordTemp.Id)"/>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </td>
        <td width="85" valign="top" align="center">
            <dl class="filemanage_right_dl">
                <dd id="btnAddEntry"><a href="@Url.Action("SaveKeywordTemplate", "Case")">@Resources.Resource.Button_Add</a></dd>      
            </dl>
        </td>
    </tr>
</table>
@Html.Pager(Model, new PagerOptions
{
    PageIndexParameterName = "pageIndex",
    CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>",
    NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>",
    CssClass = "pages",
    SeparatorHtml = ""
})
@section css
{
    <style type="text/css">
        .editor-entry .editor-label {
            width: 100px;
        }
    </style>
}
@section javascript
{
    <script type="text/javascript">
        $(function() {
            $('#btnAddEntry').click(0, openEntry);
        });

        function openEntry(entryId) {
            var title;
            if (entryId > 0) {
                title = '@Resources.Resource.Button_Alter';
            } else {
                entryId = 0;
                title = '@Resources.Resource.Button_Add';
            }
            entryId = (entryId || -1);
            var opts = {
                url: '@Url.Action("SaveKeywordTemplate", "Case")?entryId=' + entryId + '&__randomDate=' + (new Date()).getTime(),
                title: title,
                height: 230,
                width: 600,
                buttons: {
                    '@Resources.Resource.Button_Save': saveEntry,
                    '@Resources.Resource.Button_Cancel': $.closeWindow
                },
                loadedFun: function () {
                    $.validator.unobtrusive.parse($.globalIds.tempWindow);
                    $($.globalIds.tempFormInWindow).submit(function() {
                        saveEntry();
                        return false;
                    });
                }
            };
            $.openWindow(opts);
            return false;
        }

        function saveEntry() {
            var $saveForm = $($.globalIds.tempFormInWindow);
            if ($saveForm.valid()) {
                var keywordTemp = {};
                keywordTemp.KeywordName = $saveForm.find('#KeywordName').val().trim();
                keywordTemp.ID = $saveForm.find('#Id').val();
                $.ajax({
                    url: '@Url.Action("SaveKeywordTemplate", "Case")',
                    type: 'post',
                    dataType: 'json',
                    data: keywordTemp,
                    cache: false,
                    success: function(result) {
                        if (result.Success && result.Expandos) {
                            window.location.reload();
                            return;
                        }
                        alert(result.Message);
                    }
                });
            }
        }

        function deleteEntry(entryId) {
            if (!window.confirm('@Resources.MessageResource.Delete_Confirm')) return;
            $.showLoading('@Resources.MessageResource.Delete_Loading');
            $.ajax({
                url: '@Url.Action("DeleteKeywordTemplate", "Case")',
                type: 'post',
                cache: false,
                dataType: 'json',
                data: { entryId: entryId },
                success: function(result) {
                    if (result.Success) {
                        window.location.reload();
                        return;
                    }
                    alert(result.Message);
                    $.hideLoading();
                }
            });
        }
    </script>
}
